package com.rear.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import com.rear.entity.AppMessageEntity;
import com.rear.service.AppMessageService;
import com.rear.utils.PageUtils;
import com.rear.utils.R;


/**
 * 
 * 
 * @author October
 * @email chenzeming@9an-data.com
 * @date 2017-04-17 14:34:49
 */
@Controller
@RequestMapping("appmessage")
public class AppMessageController {
	@Autowired
	private AppMessageService appMessageService;
	
	@RequestMapping("/appmessage.html")
	public String list(){
		return "appmessage/appmessage.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("appmessage:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		//查询列表数据
		List<AppMessageEntity> appMessageList = appMessageService.queryList(map);
		int total = appMessageService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(appMessageList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("appmessage:info")
	public R info(@PathVariable("id") Integer id){
		AppMessageEntity appMessage = appMessageService.queryObject(id);
		
		return R.ok().put("appMessage", appMessage);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("appmessage:save")
	public R save(@RequestBody AppMessageEntity appMessage){
		appMessageService.save(appMessage);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("appmessage:update")
	public R update(@RequestBody AppMessageEntity appMessage){
		appMessageService.update(appMessage);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("appmessage:delete")
	public R delete(@RequestBody Integer[] ids){
		appMessageService.deleteBatch(ids);
		
		return R.ok();
	}
	/**
	 * 查询操作主题列表数据
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/select")
	@RequiresPermissions("appmessage:list")
	public R select(){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", 0);
		map.put("limit", 300);
		
		//查询列表数据
		List<AppMessageEntity> appMessageList = appMessageService.queryList(map);
		return R.ok().put("list", appMessageList);
	}
}
